package net.huashitong.ssydt.provider.task.service;


import net.huashitong.ssydt.base.dao.LongMapper;
import net.huashitong.ssydt.base.service.AbstractLongService;
import net.huashitong.ssydt.provider.task.mapper.SsTaskCardRecordMapper;
import net.huashitong.ssydt.task.entity.SsTaskCardRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author <a href="mailto:yhy23456@163.com">huiyang.yu</a>
 * @since 2018.01.10
 */
@Service
@Transactional
public class SsTaskCardRecordServiceImpl extends AbstractLongService<SsTaskCardRecord> implements SsTaskCardRecordService {

    private SsTaskCardRecordMapper mapper;

    @Autowired
    public SsTaskCardRecordServiceImpl(SsTaskCardRecordMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    protected LongMapper<SsTaskCardRecord> getLongMapper() {
        return this.mapper;
    }

    @Override
    public int countByYearMonthsWithUserId(String yearMonths, String userId) {
        SsTaskCardRecord record = new SsTaskCardRecord();
        record.setUserId(userId);
        record.setYearMonths(yearMonths);
        return this.mapper.countByYearMonthsWithUserId(record);
    }

    @Override
    public SsTaskCardRecord getByCardIdWihUserId(Long cardId, String userId) {
        SsTaskCardRecord record = new SsTaskCardRecord();
        record.setCardId(cardId);
        record.setUserId(userId);
        return this.mapper.getByCardIdWihUserId(record);
    }

    @Override
    public Integer countByUserIdWithReadState(String userId, byte readState) {
        SsTaskCardRecord record = new SsTaskCardRecord();
        record.setUserId(userId);
        record.setIsRead(readState);
        return this.mapper.countByUserIdWithReadState(record);
    }

    @Override
    public int updateReadStateToRead(String userId) {
        return this.mapper.updateReadStateToRead(userId);
    }

    @Override
    public List<SsTaskCardRecord> findCardRecordByUserId(String userId) {
        return this.mapper.findCardRecordByUserId(userId);
    }
}
